package streaminterface;

import com.sun.org.apache.xpath.internal.SourceTree;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

/**
 * 比较常用的一个方法,遍历的效率也是最高的.
 * Created by ydw on 2017/6/26.
 */
public class StreamInterface {
   static List<Integer> list=new ArrayList();

    public static void main(String[] args) {
        List<Integer> list = getList(StreamInterface.list);
        List<String> stringCollection = new ArrayList<>();
        stringCollection.add("ddd2");
        stringCollection.add("aaa2");
        stringCollection.add("bbb1");
        stringCollection.add("aaa1");
        stringCollection.add("bbb3");
        stringCollection.add("ccc");
        stringCollection.add("bbb2");
        stringCollection.add("ddd1");

        filter(stringCollection);
    }


    public static List<Integer> getList(List<Integer> list){
        list.add(1);
        list.add(2);
        list.add(13);
        list.add(14);
        list.add(15);
        list.add(16);
        return list;
    }
    /**
     * 集合的过滤   Filter
     */
    public static void filter(List<String> list){
        list.stream()
                .filter((s) -> s.startsWith("a"))
                .forEach(System.out::println);
    }
}
